package com.linyaonan.leetcode.easy._25;

class Solution {
    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        ListNode first = new ListNode(0);
        ListNode result = first;
        boolean flag = true;
        while (flag) {
            if (l1 == null) {
                first.next = l2;
                break;
            }
            if (l2 == null) {
                first.next = l1;
                break;
            }
            if (l1.val <= l2.val) {
                first.next = new ListNode(l1.val);
                l1 = l1.next;
            } else {
                first.next = new ListNode(l2.val);
                l2 = l2.next;
            }
            first = first.next;
        }

        return result.next;
    }
}